<% layout('/layouts/default.html', {title: '预付款查询', libs: ['validate','dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text('预付款详情')}

				<% if ((tprepayment.billStatus == "1"||tprepayment.billStatus == "4") && hasPermi('prepay:tprepayment:edit')){ %>
					<a href="#" id="tijiao"
					   class="btn btn-primary" title="${text('提交')}"
					   data-layer="true" data-layer-width="400" data-layer-height="200"
					> ${text('提交')}</a>
				<% }%>

				<% if (tprepayment.status1 != "5" && hasPermi('prepay:tprepayment:cancel')){ %>
				<a href="#" id="zuofei"
				   class="btn btn-primary" title="${text('作废')}"
				   data-layer="true" data-layer-width="400" data-layer-height="200"
				> ${text('作废')}</a>
				<% }%>

				<% if (tprepayment.billStatus == "2" && hasPermi('prepay:tprepayment:approve')){ %>
				<a href="#" id="jujue"
				   class="btn btn-primary" title="${text('拒绝')}"
				   data-layer="true" data-layer-width="400" data-layer-height="200"
				> ${text('拒绝')}</a>
				<% }%>

				<% if (tprepayment.billStatus == "2" && hasPermi('prepay:tprepayment:approve')){ %>
				<a href="#" id="tongguo"
				   class="btn btn-primary" title="${text('通过')}"
				   data-layer="true" data-layer-width="400" data-layer-height="200"
				> ${text('通过')}</a>
				<% }%>
				<% if (tprepayment.billStatus == "3" && hasPermi('pay:tpayment:yfklr')){ %>
				<input type="button" class="btn  btn-primary" id="btnFinancial111"  value="${text('预付款录入')}" />
				<% }%>
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<div id="add">
			<div class="box-body">
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('车架号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="prepaymentCode" class="form-control" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('付款方式')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="supplierId" dictType="pay_type" class="form-control required" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('预付类型')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="prepaymentType" items="${fixedExpenseList}" itemLabel="fixedExpenseName" itemValue="fixedExpenseId" class="form-control required" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('行号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="rowNumber" items="${numberList}"  class="form-control required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('车辆名')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="carnames"  class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('付款银行')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="paymentBank"  items="${taccountList}" itemLabel="accountName" itemValue="accountId" class="form-control required" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('付款日期')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="date" readonly="true" maxlength="20" class="form-control laydate"
								dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
							</div>
						</div>
					</div>

					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('付款金额')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="paymentAccount" maxlength="100" class="form-control"/>
							</div>
						</div>
					</div>
				</div>

			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<% if (hasPermi('prepay:tprepayment:edit')){ %>
						<button type="button" class="btn btn-sm btn-primary" id="btnS"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnC" ><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</div>
		<#form:form id="inputForm" model="${tprepayment}" action="${ctx}/prepay/tprepayment/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<#form:hidden path="prepaymentId"/>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('编号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="prepaymentCode" maxlength="100" class="form-control required" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('供应商')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="supplierId" items="${supplierList}" itemLabel="supplierName" itemValue="supplierId" dictType="" class="form-control required"  readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('日期')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="date" readonly="true" maxlength="20" class="form-control"  readonly="true"
									dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('状态')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="status1" dictType="payment_bill_type" blankOption="true" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('服务订单')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="serviceOrderId" items="${serviceOrderList}" itemLabel="serviceOrderCode" itemValue="serviceOrderId"  dictType="" class="form-control required"  readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('付款账号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="paymentAccount" maxlength="100" class="form-control"  readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('币种')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="currency" dictType="sys_bizhongy" class="form-control required"  readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('预付款余额')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="prepaymentBalance" class="form-control number" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('前置单据类型')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="parentBillType" dictType="erp_record_type"  maxlength="500" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>

					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('前置单据编号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="parentBillCode1"  maxlength="500" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('备注信息')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="remarks" rows="4" maxlength="500" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
				</div>

				<h4 class="form-unit">${text('预计付款明细')}</h4>
				<div class="ml10 mr10">
					<table id="tprepaymentEstimatedDataGrid"></table>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('预计付款合计')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="estimatedPaymentAmount" maxlength="100" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
				</div>
				<h4 class="form-unit">${text('实际预付款明细')}</h4>
				<div class="ml10 mr10">
					<table id="tprepaymentActualDataGrid"></table>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('实际付款合计')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="actualPaymentAmount" maxlength="100" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
				</div>

				<h4 class="form-unit">${text('系统信息')}</h4>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required hide">*</span> ${text('创建者')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="createBy" maxlength="64" class="form-control" disabled="true"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required hide">*</span> ${text('创建时间')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="createDate" readonly="true" maxlength="20" class="form-control" disabled="true"
							dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required hide">*</span> ${text('更新者')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="updateBy" maxlength="64" class="form-control" disabled="true"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required hide">*</span> ${text('更新时间')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="updateDate" readonly="true" maxlength="20" class="form-control" disabled="true"
							dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
						</div>
					</div>
				</div>
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
						<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
//初始化预计付款明细DataGrid对象
$("#tprepaymentEstimatedDataGrid").dataGrid({

	data: ${toJson(tprepayment.tprepaymentEstimatedList)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度

	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:true, hidden:true},
		{header:'主键', name:'prepaymentEstimatedId', editable:true, hidden:true},
		{header:'${text("车架号")}', name:'frameNumber', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control','readonly':'true'}},
		{header:'${text("行号")}', name:'rowNumber', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control','readonly':'true'}},
		{header:'${text("车辆名称")}', name:'carName', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control','readonly':'true'}},
		{header:'${text("付款类型")}', name:'prepaymentTypeName', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control','readonly':'true'}},
		{header:'${text("类型")}', name:'prepaymentType', width:150, editable:true, edittype:'text', hidden:true, editoptions:{'class':'form-control','readonly':'true'}},
		{header:'${text("预付款ID")}', name:'prepaymentId.prepaymentId', editable:true, hidden:true},
		{header:'${text("预计付款金额")}', name:'estimatedPaymentAmount', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number','readonly':'true'}},
		{header:'${text("实际付款合计")}', name:'paymentSumActual', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number','readonly':'true'}},
		{header:'${text("已核销金额")}', name:'paymentAmountActual', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number','readonly':'true'}},
		{header:'${text("未核销金额")}', name:'paymentAmountEstimated', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number','readonly':'true'}},
		{header:'${text("操作")}', name:'actions', hidden: true}
	],
	
	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#tprepaymentEstimatedDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowInitData: {prepaymentEstimatedId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据
	
	// 编辑表格的提交数据参数
	editGridInputFormListName: 'tprepaymentEstimatedList', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,carName,rowNumber,prepaymentEstimatedId,frameNumber,prepaymentType,estimatedPaymentAmount,prepaymentId.prepaymentId,paymentSumActual,paymentAmountActual,paymentAmountEstimated,', // 提交数据列表的属性字段
	
	// 加载成功后执行事件
	ajaxSuccess: function(data){

	}
});
//初始化实际预付款明细DataGrid对象
$("#tprepaymentActualDataGrid").dataGrid({

	data: ${toJson(tprepayment.tprepaymentActualList)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度

	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:true, hidden:true},
		{header:'主键', name:'prepaymentActualId', editable:true, hidden:true},
		{header:'${text("车架号")}', name:'frameNumber', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control','readonly':'true'}},
		{header:'${text("行号")}', name:'rowNumber', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control','readonly':'true'}},
		{header:'${text("付款银行")}', name:'paymentBankName', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control','readonly':'true'}},
		{header:'${text("银行")}', name:'paymentBank', width:150, editable:true, edittype:'text', hidden:true,editoptions:{'maxlength':'100', 'class':'form-control','readonly':'true'}},
		{header:'${text("车辆名称")}', name:'carName', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control','readonly':'true'}},
		{header:'${text("付款方式")}', name:'paymentMethod', width:150, editable:true,  edittype:'select', editoptions:{'class':'form-control',
				items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('pay_type')}),
				itemLabel: 'dictLabel', itemValue: 'dictValue'}},
		//{header:'付款方式', name:'paymentMethod', editable:true, hidden:true},
		{header:'${text("付款类型")}', name:'prepaymentTypeName', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control','readonly':'true'}},
		{header:'${text("类型")}', name:'prepaymentType', width:150, editable:true, edittype:'text', hidden:true, editoptions:{'class':'form-control','readonly':'true'}},

		{header:'${text("实际预付款金额")}', name:'actualPrepaymentAmount', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number','readonly':'true'}},
		{header:'${text("付款日期")}', name:'date', width:150, 
			formatter:'date', formatoptions:{srcformat:'Y-m-d ',newformat:'Y-m-d '},
			editable:true, edittype:'text', editoptions:{'class':'form-control laydate', 'readonly':'true',
			}
		},
		{header:'${text("创建者")}', name:'createBy', editable:true,edittype:'text', editoptions:{'class':'form-control ', 'readonly':'true',
		}},
		{header:'${text("创建时间")}', name:'createDate', editable:true,edittype:'text', editoptions:{'class':'form-control ', 'readonly':'true',
		}},
		{header:'${text("预付款ID")}', name:'prepaymentId.prepaymentId', editable:true, hidden:true},
		{header:'${text("操作")}', name:'actions', width:80, sortable:false, fixed:true, formatter: function(val, obj, row, act){
				var actions = [];
				if (val == 'new'){
					actions.push('<a href="javascript:void(0);" onclick="delData(\''+obj.rowId+'\')"><i class="fa fa-trash-o"></i></a>&nbsp;');
				}else{
				//	actions.push('<a href="javascript:void(0);" onclick="delData(\''+obj.rowId+'\')"><i class="fa fa-trash-o"></i></a>&nbsp;');
				}
				return actions.join('');
			}, editoptions: {defaultValue: 'new'}}
	],
	
	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#tprepaymentActualDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowInitData: {prepaymentActualId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据
	
	// 编辑表格的提交数据参数
	editGridInputFormListName: 'tprepaymentActualList', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,carName,rowNumber,prepaymentActualId,prepaymentType,frameNumber,paymentMethod,paymentBank,actualPrepaymentAmount,date,createBy,createDate,prepaymentId.prepaymentId,', // 提交数据列表的属性字段
	
	// 加载成功后执行事件
	ajaxSuccess: function(data){

	}
});
</script>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});



$(function () {
	var billId = "${tprepayment.parentBillCode}";
	var billCode = "${tprepayment.parentBillCode1}";
	var option = $("<option>").attr({
		"value": billId
	}).text(billCode);
	$("#parentBillCode1").append(option);
	$("#parentBillCode1 parentBillCode:first").prop("selected", 'selected');
	$("#parentBillCode1").change();
//通过
	$("#tongguo").click(function () {
		$.ajax({
			type: "post",
			url: "${ctx}/prepay/tprepayment/updateFinancialRecognition?apId=${tprepayment.prepaymentId}&sta=3",
			success: function(data){
				js.confirm(data,function () {
							location.reload(true)
				})
			}
		});
	})

	//提交
	$("#tijiao").click(function () {
		$.ajax({
			type: "post",
			url: "${ctx}/prepay/tprepayment/updateFinancialRecognition?apId=${tprepayment.prepaymentId}&sta=2",
			success: function(data){
				js.confirm(data,function () {
					location.reload(true)
				})
			}
		});
	})

	//拒绝
	$("#jujue").click(function () {
		$.ajax({
			type: "post",
			url: "${ctx}/prepay/tprepayment/updateFinancialRecognition?apId=${tprepayment.prepaymentId}&sta=4",
			success: function(data){
				js.confirm(data,function () {
					location.reload(true)
				})
			}
		});
	})

	//作废
	$("#zuofei").click(function () {
		$.ajax({
			type: "post",
			url: "${ctx}/prepay/tprepayment/updateFinancialRecognition?apId=${tprepayment.prepaymentId}&sta=5",
			success: function(data){
				js.confirm(data,function () {
					location.reload(true)
				})
			}
		});
	})
})
</script>
<script>
	//改变样式
	$(function () {
		$("#add").css("margin-bottom","-1000px")
		$("#add").css("z-index","1000")
		$("#add").css("background-color","#eee")
		$("#add").css("width","600px")
		$("#add").css("margin-left","300px")
		$("#add").css("float","left")
		$("#add").css("position","absolute")
		$("#add").css("display","none")
		$("#add").css("border","1px solid #222")
		$("#status12").val($("#status1").val())


		//填写预付款
		$("#btnS").click(function () {
			var h1=	$("#add").find("#select2-prepaymentCode-container").html();
			var h2=	$("#add").find("select[id=\"supplierId\"]").val();
			var h3=	$("#add").find("select[id='paymentBank']").val();
			var h4=	$("#add").find("input[id=\"date\"]").val();
			var h5=	$("#add").find("input[id=\"paymentAccount\"]").val();
			var h6= $("#add").find("select[id='prepaymentType']").val();

			var h7= $("#add").find("select[id='prepaymentType']").find("option[value="+h6+"]").html();
			var h8= $("#add").find("select[id='supplierId']").find("option[value="+h2+"]").html();
			var h9= $("#add").find("select[id='paymentBank']").find("option[value="+h3+"]").html();
			var h10=$("#add").find("#carnames").val();
			var h11=$("#add").find("#select2-rowNumber-container").html();

			var text =/^[0-9][0-9]*(\.[0-9]*)?$/;
			if(text.test(h5)==false){
				js.showMessage("请输入正确的付款金额");
				return;
			}
			if(h11==""||h11==null||h2==""||h2==null||h3==""||h3==null||h5==""||h5==null|h6==""||h6==null){
				js.showMessage("请完善信息");
				return;
			}
			var data ={}
			if(h1!=null&&h1!=NaN&&h1!=""){
				data.frameNumber=h1;
			}
			data.paymentMethod=h2;
			data.paymentBank=h3;
			data.date=h4;
			data.actualPrepaymentAmount=h5;
			data.prepaymentType=h6;
			data.prepaymentTypeName=h7;
			data.paymentMethod1=h8;
			data.paymentBankName=h9;
			data.carName=h10;
			data.rowNumber=h11;

			$('#tprepaymentActualDataGrid').jqGrid('addRow', { position: 'last',
				addRowParams: {keys: false, focusField: true},
				initdata: data
			});

			var list=$("#tprepaymentEstimatedDataGrid").find("input[name='rowNumber']")
			var flag =false;
			list.each(function () {
				//付款类型
				var ftype =$(this).parent().parent().find("input[name='prepaymentType']").val();

				//上面找的到
				if($(this).val()==h11&&ftype==h6){
					//未核销金额
					var m =$(this).parent().parent().find("input[name='paymentAmountEstimated']").val();
					m=parseFloat(m);
					h5=parseFloat(h5)
					m=m+h5;
					$(this).parent().parent().find("input[name='paymentAmountEstimated']").val(m)
					//类型
					$(this).parent().parent().find("input[name='prepaymentType']").val(h6)
					//实际收款合计
					var mon =$(this).parent().parent().find("input[name='paymentSumActual']").val();
					if(mon!=null&&mon!=""&&mon!=NaN){
						$(this).parent().parent().find("input[name='paymentSumActual']").val(parseFloat(mon)+parseFloat(h5));
					}else{
						$(this).parent().parent().find("input[name='paymentSumActual']").val(parseFloat(h5));
					}
					flag=true;
					return false;
				}
			})
			//上面找不到
			if(flag==false){
				var dates ={}
				if(h1!=null&&h1!=NaN&&h1!=""){
					dates.frameNumber=h1;
				}
				dates.paymentAmountActual=0;
				dates.paymentAmountEstimated=h5;
				dates.prepaymentType=h6;
				dates.prepaymentTypeName=h7;
				dates.paymentSumActual=h5;
				dates.carName=h10;
				dates.rowNumber=h11;

				$('#tprepaymentEstimatedDataGrid').jqGrid('addRow', { position: 'last',
					addRowParams: {keys: false, focusField: true},
					initdata: dates
				});

			}
			//上面余额赋值
			var count =$("#prepaymentBalance").val();
			if(count==null||count==NaN||count==""){
				$("#prepaymentBalance").val(h5)
			}else{
				$("#prepaymentBalance").val(parseFloat(count)+parseFloat(h5))
			}

			//添加完改变回空值
			$("#add").find("input[id=\"date\"]").val("");
			$("#add").find("input[id=\"paymentAccount\"]").val("");
			//改变金额
			changeMoney()
			$("#add").css("display","none")
		})



		$("#btnC").click(function () {
			$("#add").css("display","none")
		})
		$("#btnFinancial111").click(function () {
			$("#add").css("display","block")
		})

	})

	//车架号
$(function () {

		if ($("#serviceOrderId").val() != "") {
			$.ajax({
				type: "POST",
				url: "${ctx}/payment/tap/getFrameNumberList",
				data: {
					"serviceOrderId": $("#serviceOrderId").val(),
				},
				success: function (data) {
					//根据订单编号赋值车架号
					$("#prepaymentCode").html("")
					if (data.length > 0) {
						for (var i = 0; i < data.length; i++) {
							var frameNumber1 = data[i].frameNumber;
							if(data[i].frameNumber!=""&&data[i].frameNumber!=null){
								$("#prepaymentCode").append("<option value="+frameNumber1+">"+frameNumber1+"</option>")

							}
							//$("#prepaymentCode").append("<option value="+frameNumber1+">"+frameNumber1+"</option>")
						}

					}

				}
			});
		}

})

	//删除行
	function delData(rowId) {

		js.confirm("你确认要删除这条数据吗？",function () {
			var number=	$('tr[id='+rowId+']').find("input[name='rowNumber']").val();
			var type=	$('tr[id='+rowId+']').find("input[name='prepaymentType']").val();
			var money=	$('tr[id='+rowId+']').find("input[name='actualPrepaymentAmount']").val();

			var list=$("#tprepaymentEstimatedDataGrid").find("input[name='rowNumber']")
			list.each(function () {

				var ftype =$(this).parent().parent().find("input[name='prepaymentType']").val();
				if($(this).val()==number&&ftype==type){
					var m =$(this).parent().parent().find("input[name='paymentAmountEstimated']").val();
					var mon =$(this).parent().parent().find("input[name='paymentSumActual']").val();

					m=parseFloat(m)-parseFloat(money)
					mon=parseFloat(mon)-parseFloat(money)

					//赋值
					$(this).parent().parent().find("input[name='paymentAmountEstimated']").val(m);
					$(this).parent().parent().find("input[name='paymentSumActual']").val(mon);

					return false;
				}
			})
			//上面余额赋值
			var sum=0;
			$("input[name='paymentAmountEstimated']").each(function () {
				sum+=parseFloat($(this).val())
			})
			$("#prepaymentBalance").val(sum)
			//删除行
			$('#tprepaymentActualDataGrid').dataGrid('delRowData', rowId);
			changeMoney()
		})

	}

	//给车架号，行号添加change事件
	$(function () {
		//行号
		$("#rowNumber").change(function () {

			//var f =$("#prepaymentCode").val()
			var row =$("#rowNumber").val()
			var ser =$("#serviceOrderId").val()

			$.ajax({
				type: "POST",
				url: "${ctx}/prepay/tprepayment/findByMany",
				datatype:"json",
				data: {
					fram :"",
					row:row,
					ser:ser
				},
				success: function (data) {

					if(data!=null&&data!=""){

					$("#prepaymentCode").find("option").each(function () {
						$(this).prop("selected",false)
						if($(this).html()==data.frameNumber){
							$(this).prop("selected",true)
						}
					})
					$("#select2-prepaymentCode-container").html(data.frameNumber)
					$("#select2-prepaymentCode-container").attr("title",data.frameNumber)
					$("#carnames").val(data.tcar.carName)
				}
				}
			});

		})

		//车架号
		$("#prepaymentCode").change(function () {

			var f =$("#prepaymentCode").val()
			//var row =$("#rownumber").val()
			var ser =$("#serviceOrderId").val()

			$.ajax({
				type: "POST",
				url: "${ctx}/prepay/tprepayment/findByMany",
				datatype:"json",
				data: {
					fram :f,
					row:"",
					ser:ser
				},
				success: function (data) {

					$("#rownumber").find("option").each(function () {
						$(this).prop("selected",false)
						if($(this).html()==data.rowNumber){
							$(this).prop("selected",true)
						}
					})
					$("#select2-rowNumber-container").html(data.rowNumber)
					$("#select2-rowNumber-container").attr("title",data.rowNumber)
					$("#carnames").val(data.tcar.carName)
				}
			});

		})
	})
	//页面加载完执行一次
	$(function () {
      //var f =$("#prepaymentCode").val()
		var row =$("#rowNumber").val()
		var ser =$("#serviceOrderId").val()

		$.ajax({
			type: "POST",
			url: "${ctx}/prepay/tprepayment/findByMany",
			datatype:"json",
			data: {
				fram :"",
				row:row,
				ser:ser
			},
			success: function (data) {

				$("#prepaymentCode").find("option").each(function () {
					$(this).prop("selected",false)
					if($(this).html()==data.frameNumber){
						$(this).prop("selected",true)
					}
				})
				$("#select2-prepaymentCode-container").html(data.frameNumber)
				$("#select2-prepaymentCode-container").attr("title",data.frameNumber)
				$("#carnames").val(data.tcar.carName)
			}
		});
	})



	//预计收款合计和实际收款合计变动
	function changeMoney() {
		//预计收款合计
		var money1 =0;
		var money2 =0;
		var list1 =$("#tprepaymentEstimatedDataGrid").find("input[name=\"estimatedPaymentAmount\"]")
		var list2 =$("#tprepaymentActualDataGrid").find("input[name=\"actualPrepaymentAmount\"]")

		list1.each(function () {
			if($(this).val()!=null&&$(this).val()!=""){
				money1 =money1+parseFloat($(this).val())
			}

		})
		list2.each(function () {
			if($(this).val()!=null&&$(this).val()!=""){
				money2 =money2+parseFloat($(this).val())
			}

		})

		$("#estimatedPaymentAmount").val(money1)
		$("#actualPaymentAmount").val(money2)
	}

	$(function () {
		changeMoney()
	})
</script>